#include "ClientRiotShield.h"

void ClientRiotShield::runLogic(){
	pthread_mutex_lock( &shieldLock );
	
	if(updated){
		myPos.x = xloc;
		myPos.y = yloc;
		myPos.z = zloc;
		myPos.vx = vx;
		myPos.vy = vy;
		myPos.vz = vz;
		updated = 0;
		//std::cout << "Client " << myID << " " << myPos.x << " " << myPos.y << " " << myPos.z << "\n";
	}
	else{
		myPos.accelerateResistance(DECELRX, DECELRY, 0);
	}
	
	pthread_mutex_unlock( &shieldLock );
}

void ClientRiotShield::messageUpdate(char *message, int length){
	pthread_mutex_lock( &shieldLock );
	//std::cout << "Client " << myID << "Got pos info\n";
	updated = 1;
	//get information
	int bufferLoc = 0;
	bufferLoc += conv.readConvertedDouble(&xloc , (message+bufferLoc));
	bufferLoc += conv.readConvertedDouble(&yloc , (message+bufferLoc));
	bufferLoc += conv.readConvertedDouble(&zloc , (message+bufferLoc));
	bufferLoc += conv.readConvertedDouble(&vx , (message+bufferLoc));
	bufferLoc += conv.readConvertedDouble(&vy , (message+bufferLoc));
	bufferLoc += conv.readConvertedDouble(&vz , (message+bufferLoc));
	//std::cout << "Client " << myID << " " << myPos.x << " " << myPos.y << " " << myPos.z << "\n";
	
	pthread_mutex_unlock( &shieldLock );
}
